use crate::unsafe_assign;
use std::cell::UnsafeCell;
use std::fmt::{Display, Formatter};
use std::mem::ManuallyDrop;
use std::rc::Rc;
use std::sync::Arc;

/// trait: sync-send
/// 基本上描述：
///
/// send: 允许T在线程之间传递（movable between threads）
///
/// sync: 允许T在线程之间共享（ shared between threads）if &T is Send then T is auto trait with Sync
///
/// 基本上所有的类型实现了 Send,Sync (otherWise *const and *mut...)
///
/// ！！！当设计一个类决定如何限制内含物是否需要实现Send，Sync最为重要的标准是，提供的Api或者功能是否允许内含物实现Send或者Sync的功能 ！！！
struct Wrap<T: Sized>(T);

impl<T: Sized + Default> Default for Wrap<T> {
    fn default() -> Self {
        Wrap(T::default())
    }
}

impl<T: Sized + Display> Display for Wrap<T> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl<T: Sized> Drop for Wrap<T> {
    fn drop(&mut self) {
        println!("!!!dropped!!!");
    }
}

#[test]
fn test11() {
    let rc = Rc::new(1);
    let arc = Arc::new(1);
    let iii = 1;

    let strs = Wrap("asd".to_string());
    let strs = &strs as *const Wrap<String> as *mut Wrap<String>;

    unsafe {
        let wrap = std::mem::take(&mut (*strs));
        println!("{}", wrap);
        // let _ = std::mem::replace(&mut (*strs), Wrap::default());
    }

    // unsafe_assign!(strs, Wrap("wangweilin".to_string()));
    // println!("{}", *strs);
}
